package com.android.jay.mvc;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.android.jay.music.R;

public class MVCActivity extends AppCompatActivity implements View.OnClickListener, MvcCallabck {

    private TextView mTv;
    private EditText mEt;

    private MVCModel mMvcModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mvc);
        initView();
        mMvcModel = new MVCModel();
    }

    private void initView() {

        mEt = findViewById(R.id.account_ed);
        mTv = findViewById(R.id.result);
        findViewById(R.id.searchbtn).setOnClickListener(this);
    }

    //获取用户输入
    private String getEnterAccount() {
        return mEt.getText().toString();
    }

    //成功展示
    private void showSuccessR(Account account) {
        mTv.setText(account.getUserName() + account.getLevel());

    }

    //成功展示
    private void showFailR() {
        mTv.setText("查询失败");

    }


    @Override
    public void onClick(View v) {
        //点击通知model去获取数据
        mMvcModel.getAccountData(getEnterAccount(), this);

    }

    @Override
    public void success(Account account) {
        showSuccessR(account);
    }

    @Override
    public void failed() {
        showFailR();

    }
}
